<?php
/**
 * @package Priya
 * @version 1.6
 */
/*
Plugin Name: Priya Test plugin
Description: This is a demo plugin to create required tables in wordpress database.
Author: Priyadharshini Asokan
Version: 1.0
*/

function my_plugin_create_tables()
{
        // do NOT forget this global
	global $wpdb;
 
	// this if statement makes sure that the table doe not exist already
	if($wpdb->get_var("show tables like priya_users") != 'priya_users') 
	{
	$sql = "CREATE TABLE wd_proj_users (
  id int(11) NOT NULL auto_increment,
  firstname varchar(50) NOT NULL,
  lastname varchar(50) NOT NULL,
  email varchar(100) NOT NULL,
  dateofbirth datetime NOT NULL,
  username varchar(60) NOT NULL,
  password varchar(65) NOT NULL,
  PRIMARY KEY  (id)
);
CREATE TABLE wd_proj_user_roles (
  userId int(11) NOT NULL,
  role varchar(45) NOT NULL,
  PRIMARY KEY  (userId,role)
);

CREATE TABLE wd_proj_submissions (
  id int(11) NOT NULL auto_increment,
  studentId int(11) default NULL,
  assignmentId int(11) default NULL,
  PRIMARY KEY  (id),
  KEY studentId_FK_idx (studentId),
  KEY `assignmentId_FK_idx` (assignmentId)
);
CREATE TABLE wd_proj_quarters (
  id int(11) NOT NULL auto_increment,
  name varchar(45) NOT NULL,
  year int(11) NOT NULL,
  PRIMARY KEY  (`id`)
);
CREATE TABLE wd_proj_enrollments (
  offeringId int(11) NOT NULL,
  studentId int(11) NOT NULL,
  PRIMARY KEY  (offeringId,studentId),
  KEY studentId_FK_idx (studentId)
);
CREATE TABLE wd_proj_courses (
  number varchar(50) NOT NULL,
  name varchar(250) NOT NULL,
  PRIMARY KEY  (`number`)
);
CREATE TABLE wd_proj_courseoffering (
  id int(11) NOT NULL auto_increment,
  courseNumber varchar(45) default NULL,
  quarterId int(11) default NULL,
  facultyId int(11) default NULL,
  PRIMARY KEY  (id),
  KEY facultyId_FK_idx (facultyId),
  KEY courseNumber_FK_idx (courseNumber),
  KEY QuarterId_FK_idx (quarterId)
);";
		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		dbDelta($sql);
	}
}
// this hook will cause our creation function to run when the plugin is activated
register_activation_hook( __FILE__, 'my_plugin_create_tables' );


?>
